// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: qiulin 1746365080@qq.com
 * @Date: 2024-10-23 16:11:24
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2024-12-07 21:33:08
 * @FilePath: /SGSim/Import/ImportAPI/ImportAPI.cpp
 */

#include "ImportAPI.h"

#include <iostream>
#include <utility>

#include <boost/algorithm/string.hpp>

#include "Utility/Logging/SGLogger.h"

#include "DBManager/DBServiceFactory.h"

#include "Import/BDFImport/BDFImport.h"

using namespace SG::Import;
using namespace SG::DataStructure;
using namespace SG::DataStructure::Common;
SGImporter::SGImporter (std::shared_ptr<SG::DBManager::DBServiceFactory> dbServiceFactory)
{
    m_dbServiceFactory = std::move (dbServiceFactory);
}

Status SGImporter::Import (const std::string& filepath)
{
    // Nastran Model Import
    if (boost::ends_with (filepath, ".bdf") || boost::ends_with (filepath, ".dat"))
    {
        auto _imp = std::make_shared<BDFImporter> (m_dbServiceFactory);
        if (_imp == nullptr)
        {
            SGError << "failed to generate Importer .";
        }
        else
        {
            if (_imp->Load (filepath.c_str ()) == Status::STATUS_Success)
            {
                SGInfo << "success  import !";
                return Status::STATUS_Success;
            }

            SGError << "failed to parse the file .";
        }
    }
    else
    {
        SGError << "unsupport the file type :" << filepath;
    }
    return Status::STATUS_Failure;
}
